package com.hydl.power.controller;

import com.hydl.power.aop.annotation.LogAnnotation;
import com.hydl.power.pojo.SysRole;
import com.hydl.power.service.SysRoleService;
import com.hydl.power.service.SysUserService;
import com.hydl.power.utils.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(value = "SysRoleController",tags = "角色控制类")
@RestController
@RequestMapping("/sysRole")
@CrossOrigin
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;


    // @LogAnnotation(module = "角色控制类",description = "角色展示")
    @PostMapping("/getAllRole")
    @ApiOperation(value = "角色展示",produces = "application/json")
    public Resp<List<SysRole>> getAllRole() {
        return Resp.success(sysRoleService.getAllRole());
    }


    @LogAnnotation(module = "角色控制类",description = "新增角色")
    @PostMapping("/addRole")
    @ApiOperation(value = "新增角色", notes = "新增角色")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "name", value = "角色名字", required = true, dataType = "String"),
    })
    public Resp saveRole(String name) {
        return Resp.success(sysRoleService.addRole(name));
    }


    @LogAnnotation(module = "角色控制类",description = "删除角色")
    @PostMapping("/deleteRoleById")
    @ApiOperation(value = "删除角色", notes = "删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "id",dataType = "Integer"),
    })
    public Resp deleteUser(Integer id){
        int i =  sysRoleService.deleteById(id);
        if (i == 1){
            return Resp.success("Success");
        }else{
            return Resp.fail("删除失败");
        }
    }

}
